﻿package 
{
	import HxGraphix;
	import flash.display.*;
	import flash.net.*;
	import flash.utils.*;

	public class Main extends Sprite
	{
		var _graphics:HxGraphix;

		public function Main()
		{
			_graphics = new HxGraphix();
			
			//rect
			_graphics.lineStyle(3, 0x000000);
			_graphics.beginFill(0xff0000, 1);
			_graphics.drawRect(10,10,100,100);
			
			//round rect
			_graphics.lineStyle(4, 0x0000ff);
			_graphics.beginFill(0x00ff00, 1);
			_graphics.drawRoundRect(120,10,100,100,20);
			
			//round rect complex
			_graphics.lineStyle(4, 0xff0000);
			_graphics.beginFill(0x0000ff, 1);
			_graphics.drawRoundRectComplex(230, 10, 100, 100, 20, 0, 0, 20);
			
			//circle
			_graphics.lineStyle(3, 0x0000ff);
			_graphics.beginFill(0xffff00, 1);
			_graphics.drawCircle(390,60,50);
			
			//ellipse
			_graphics.lineStyle(3, 0xff00ff);
			_graphics.beginFill(0x00ffff, 1);
			_graphics.drawEllipse(450,35,100,50);
			
			//curveTo
			_graphics.lineStyle(4, 0);
			_graphics.beginFill(0xFFf000,1);
			_graphics.moveTo(100, 150); 
			_graphics.curveTo(30, 200, 100, 250);    
			_graphics.curveTo(50, 200, 100, 150);
			_graphics.endFill();
			
			//triangle
			_graphics.lineStyle(4, 0);
			_graphics.beginFill(0xFFF000,1);
			_graphics.moveTo(100, 300);
			_graphics.lineTo(150,400);
			_graphics.lineTo(50,400);
			_graphics.lineTo(100, 300);
			
			//lineTo moveTo
			_graphics.lineStyle(2, 0x000000);
			_graphics.beginFill(0xffffff, 0.8);
			_graphics.moveTo(0,0);
			_graphics.lineTo(500,0);
			_graphics.lineTo(200,200);
			_graphics.lineTo(0,500);
			_graphics.lineTo(0,0);

			//lineTo, moveTo
			_graphics.lineStyle(2, 0x0000FF, 1);
			_graphics.beginFill(0xEEEEEE, 0.8);
			_graphics.moveTo(300,300);
			_graphics.lineTo(300+200,300+0);
			_graphics.lineTo(300+200,300+200);
			_graphics.lineTo(300,300+200);
			_graphics.lineTo(300,300);
			
			//var tag:TShape = _graphics.getTag(1/*id*/);
			var swf = _graphics.getSWF();
			var bytes:ByteArray = swf.getData();

			new FileReference().save(bytes, 'shapes.swf');
			
			var loader:Loader=new Loader();
			loader.loadBytes(bytes);
			addChild(loader);

			var _info:Object = _graphics.getInfo();
			trace('shape bounds:');
			trace('xMin: '+_info.rect.left);
			trace('xMax: '+_info.rect.right);
			trace('yMin: '+_info.rect.top);
			trace('yMax: '+_info.rect.bottom);
			trace('Number of shapeRecords:'+_info.recordsTotal);
		}
	}
}